home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / WarpQuake / Src / r_sky.c < prev    next >
C/C++ Source or Header  |  2000-05-22  |  5KB  |  281 lines

  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  12.  
  13. See the GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. */
  20. // r_sky.c
  21.  
  22. #include "quakedef.h"
  23. #include "r_local.h"
  24. #include "d_local.h"
  25.  
  26.  
  27. float    skyspeed, skyspeed2;
  28.  
  29. float        skytime;
  30.  
  31. byte        *r_skysource;
  32.  
  33. int r_skymade;
  34. int r_skydirect;        // not used?
  35.  
  36.  
  37. // TODO: clean up these routines
  38.  
  39. static byte    bottomsky[128*131];
  40. static byte    bottommask[128*131];
  41. static byte    newsky[128*256];    // newsky and topsky both pack in here, 128 bytes
  42.                             //  of newsky on the left of each scan, 128 bytes
  43.                             //  of topsky on the right, because the low-level
  44.                             //  drawers need 256-byte scan widths
  45.  
  46.  
  47. /*
  48. =============
  49. R_InitSky
  50.  
  51. A sky texture is 256*128, with the right side being a masked overlay
  52. ==============
  53. */
  54. void R_InitSky (texture_t *mt)
  55. {
  56.     int            i, j;
  57.     byte        *src;
  58.  
  59.     src = (byte *)mt + mt->offsets[0];
  60.  
  61.     for (i=0 ; i<128 ; i++)
  62.     {
  63.         for (j=0 ; j<128 ; j++)
  64.         {
  65.             newsky[(i*256) + j + 128] = src[i*256 + j + 128];
  66.         }
  67.     }
  68.  
  69.     for (i=0 ; i<128 ; i++)
  70.     {
  71.         for (j=0 ; j<131 ; j++)
  72.         {
  73.             if (src[i*256 + (j & 0x7F)])
  74.             {
  75.                 bottomsky[(i*131) + j] = src[i*256 + (j & 0x7F)];
  76.                 bottommask[(i*131) + j] = 0;
  77.             }
  78.             else
  79.             {
  80.                 bottomsky[(i*131) + j] = 0;
  81.                 bottommask[(i*131) + j] = 0xff;
  82.             }
  83.         }
  84.     }
  85.     
  86.     r_skysource = newsky;
  87. }
  88.  
  89.  
  90. /*
  91. =================
  92. R_MakeSky
  93. =================
  94. */
  95. void R_MakeSky (void)
  96. {
  97.     int            x, y;
  98.     int            ofs, baseofs;
  99.     int            xshift, yshift;
  100.     unsigned    *pnewsky;
  101.     static int    xlast = -1, ylast = -1;
  102.  
  103.     xshift = skytime*skyspeed;
  104.     yshift = skytime*skyspeed;
  105.  
  106.     if ((xshift == xlast) && (yshift == ylast))
  107.         return;
  108.  
  109.     xlast = xshift;
  110.     ylast = yshift;
  111.     
  112.     pnewsky = (unsigned *)&newsky[0];
  113.  
  114.     for (y=0 ; y<SKYSIZE ; y++)
  115.     {
  116.         baseofs = ((y+yshift) & SKYMASK) * 131;
  117.  
  118. // FIXME: clean this up
  119. #if UNALIGNED_OK
  120.  
  121.         for (x=0 ; x<SKYSIZE ; x += 4)
  122.         {
  123.             ofs = baseofs + ((x+xshift) & SKYMASK);
  124.  
  125.         // PORT: unaligned dword access to bottommask and bottomsky
  126.  
  127.             *pnewsky = (*(pnewsky + (128 / sizeof (unsigned))) &
  128.                         *(unsigned *)&bottommask[ofs]) |
  129.                         *(unsigned *)&bottomsky[ofs];
  130.             pnewsky++;
  131.         }
  132.  
  133. #else
  134.  
  135.         for (x=0 ; x<SKYSIZE ; x++)
  136.         {
  137.             ofs = baseofs + ((x+xshift) & SKYMASK);
  138.  
  139.             *(byte *)pnewsky = (*((byte *)pnewsky + 128) &
  140.                         *(byte *)&bottommask[ofs]) |
  141.                         *(byte *)&bottomsky[ofs];
  142.             pnewsky = (unsigned *)((byte *)pnewsky + 1);
  143.         }
  144.  
  145. #endif
  146.  
  147.         pnewsky += 128 / sizeof (unsigned);
  148.     }
  149.  
  150.     r_skymade = 1;
  151. }
  152.  
  153.  
  154. /*
  155. =================
  156. R_GenSkyTile
  157. =================
  158. */
  159. void R_GenSkyTile (void *pdest)
  160. {
  161.     int            x, y;
  162.     int            ofs, baseofs;
  163.     int            xshift, yshift;
  164.     unsigned    *pnewsky;
  165.     unsigned    *pd;
  166.  
  167.     xshift = skytime*skyspeed;
  168.     yshift = skytime*skyspeed;
  169.  
  170.     pnewsky = (unsigned *)&newsky[0];
  171.     pd = (unsigned *)pdest;
  172.  
  173.     for (y=0 ; y<SKYSIZE ; y++)
  174.     {
  175.         baseofs = ((y+yshift) & SKYMASK) * 131;
  176.  
  177. // FIXME: clean this up
  178. #if UNALIGNED_OK
  179.  
  180.         for (x=0 ; x<SKYSIZE ; x += 4)
  181.         {
  182.             ofs = baseofs + ((x+xshift) & SKYMASK);
  183.  
  184.         // PORT: unaligned dword access to bottommask and bottomsky
  185.  
  186.             *pd = (*(pnewsky + (128 / sizeof (unsigned))) &
  187.                    *(unsigned *)&bottommask[ofs]) |
  188.                    *(unsigned *)&bottomsky[ofs];
  189.             pnewsky++;
  190.             pd++;
  191.         }
  192.  
  193. #else
  194.  
  195.         for (x=0 ; x<SKYSIZE ; x++)
  196.         {
  197.             ofs = baseofs + ((x+xshift) & SKYMASK);
  198.  
  199.             *(byte *)pd = (*((byte *)pnewsky + 128) &
  200.                         *(byte *)&bottommask[ofs]) |
  201.                         *(byte *)&bottomsky[ofs];
  202.             pnewsky = (unsigned *)((byte *)pnewsky + 1);
  203.             pd = (unsigned *)((byte *)pd + 1);
  204.         }
  205.  
  206. #endif
  207.  
  208.         pnewsky += 128 / sizeof (unsigned);
  209.     }
  210. }
  211.  
  212.  
  213. /*
  214. =================
  215. R_GenSkyTile16
  216. =================
  217. */
  218. void R_GenSkyTile16 (void *pdest)
  219. {
  220.     int                x, y;
  221.     int                ofs, baseofs;
  222.     int                xshift, yshift;
  223.     byte            *pnewsky;
  224.     unsigned short    *pd;
  225.  
  226.     xshift = skytime * skyspeed;
  227.     yshift = skytime * skyspeed;
  228.  
  229.     pnewsky = (byte *)&newsky[0];
  230.     pd = (unsigned short *)pdest;
  231.  
  232.     for (y=0 ; y<SKYSIZE ; y++)
  233.     {
  234.         baseofs = ((y+yshift) & SKYMASK) * 131;
  235.  
  236. // FIXME: clean this up
  237. // FIXME: do faster unaligned version?
  238.         for (x=0 ; x<SKYSIZE ; x++)
  239.         {
  240.             ofs = baseofs + ((x+xshift) & SKYMASK);
  241.  
  242.             *pd = d_8to16table[(*(pnewsky + 128) &
  243.                     *(byte *)&bottommask[ofs]) |
  244.                     *(byte *)&bottomsky[ofs]];
  245.             pnewsky++;
  246.             pd++;
  247.         }
  248.  
  249.         pnewsky += TILE_SIZE;
  250.     }
  251. }
  252.  
  253.  
  254. /*
  255. =============
  256. R_SetSkyFrame
  257. ==============
  258. */
  259. void R_SetSkyFrame (void)
  260. {
  261.     int        g, s1, s2;
  262.     float    temp;
  263.     int        iskyspeed = 8;
  264.     int        iskyspeed2 = 2;
  265.  
  266.     skyspeed = iskyspeed;
  267.     skyspeed2 = iskyspeed2;
  268.  
  269.     g = GreatestCommonDivisor (iskyspeed, iskyspeed2);
  270.     s1 = iskyspeed / g;
  271.     s2 = iskyspeed2 / g;
  272.     temp = SKYSIZE * s1 * s2;
  273.  
  274.     skytime = cl.time - ((int)(cl.time / temp) * temp);
  275.     
  276.  
  277.     r_skymade = 0;
  278. }
  279.  
  280.  
  281.